var headmasterListUrl = basePath + "/sys/report/headmaster/list";
var headmasterDelUrl = basePath + "/sys/report/headmaster/del";
var headmasterAddAndUpdateUrl = basePath + "/sys/report/headmaster/addAndUpdate";

var dataGrid;
$(function() {
	loadData();
});

function loadData() {
	dataGrid = $('#notice').datagrid({
		url : headmasterListUrl,
		toolbar: '#tb',
		fit : true,
		fitColumns : true,
		border : true,
		pagination : true,
		idField : 'id',
		pageSize : config.pageSize,
		autoRowHeight : 140,
		pageList : config.pageList,
		queryParams : {
			resourceRange: $("#sendTimeQuery").val(),
			resourceRange: $("#replyTimeQuery").val(),
			resourceRange: $("#isReply").val()
		},
		nowrap : true,
		striped : true,
		rownumbers : true,
		columns : [ [  
		{
			field : 'id',
			width : 10,
			align : "center",
			checkbox : true
		}, 
		{ 
			field : 'grade',
			title : '年级',
			resizable : true,
			align : "center",
			width : 5
			
		}, 
		{ 
			field : 'clazz',
			title : '班级',
			resizable : true,
			align : "center",
			width : 5
			
		}, 
		{ 
			field : 'studentName',
			title : '学生姓名',
			resizable : true,
			align : "center",
			width : 10
			
		}, 
		{ 
			field : 'parentName',
			title : '家长姓名',
			resizable : true,
			align : "center",
			width : 10
			
		}, 
		{ 
			field : 'teacherName',
			title : '教师姓名',
			resizable : true,
			align : "center",
			width : 10
		}, 
		{
			field : 'problem',
			title : '内容',
			width : 20,
			align : "center"
		}, 
		{
			field : 'createTime',
			title : '发送时间',
			width : 15,
			align : "center",
			formatter:function(value,row,index){
				if(value != null){
				    var date = new Date(value);
			        return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate() + " "+ date.getHours() + ":" + date.getMinutes()  + ":" + date.getSeconds() ;
				}else{
					return "";
				}
            }
		}, 
		{
			field : 'reply',
			title : '回复',
			width : 20,
			align : "center",
			editor:{type:'validatebox'}
		}, 
		{
			field : 'replyTime',
			title : '回复时间',
			width : 15,
			align : "center",
			formatter:function(value,row,index){
				if(value != null){
				    var date = new Date(value);
			        return date.getFullYear()+"-"+(date.getMonth()+1)+"-"+date.getDate() + " "+ date.getHours() + ":" + date.getMinutes()  + ":" + date.getSeconds() ;
				}else{
					return "";
				}
            }
		}, 
		{
			field : 'replyStatus',
			title : '回复状态',
			width : 10,
			align : "center"
		},
		
		
		
		] ],
		onAfterEdit : function(rowIndex, rowData, changes){
			if(rowData.id){
				changes.id = rowData.id;
				changes.resourceRange = $("#resourceRange").val();
				addmodify(changes);
			}else {
				rowData.resourceRange = $("#resourceRange").val();
				addmodify(rowData);
			}
		}
	});
}

function reload() {
	dataGrid.datagrid("clearSelections");
	searchForm("searchForm");
}

function searchForm(formId) {
	dataGrid.datagrid('load', $.serializeObject($('#' + formId)));
}
function resetForm(formId) {
	$("#" + formId)[0].reset();
}
function exportToExcel(searchForm,exportUrl) {
	$("#" + searchForm).attr('action',exportUrl);
	$("#" + searchForm).submit();  
	resetForm(searchForm);
}